package bawei.com.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.NestedScrollView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import bawei.com.bilibili.ActivityCenterActivity;
import bawei.com.bilibili.AllareasRankActivity;
import bawei.com.bilibili.GameCentreActivity;
import bawei.com.bilibili.OriginalRankActivity;
import bawei.com.bilibili.R;
import bawei.com.bilibili.TopicActivity;
import bawei.com.bilibili.WebViewActivity;
import bawei.com.model.Network;
import bawei.com.widget.FlowLayout;

import static bawei.com.bilibili.R.id.ss;


/**
 * 类描述:展示发现页面的fragment
 * 作者：张宏达
 * 时间:2017/3/9 15:49
 * 邮箱:18310832074@163.com
 */

public class FindFragment extends Fragment implements View.OnClickListener {

    int STATUS = 0;

    NestedScrollView nestedScrollView;
    FlowLayout fll_flowlayout_show;
    ImageView iv_findfragment_scan;
    TextView ed_findfragment_seek;
    TextView tv_findfragment_more;
    LinearLayout lay_findfragment_xingqu;
    LinearLayout lay_findfragment_huati;
    LinearLayout lay_findfragment_huodong;
    LinearLayout lay_findfragment_xiaohei;
    LinearLayout lay_findfragment_yuanchuang;
    LinearLayout lay_findfragment_quanqu;
    LinearLayout lay_findfragment_youxi;
    LinearLayout lay_findfragment_zhoubian;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //加载布局
        return inflater.inflate(R.layout.findfragment, null);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        initWeight();

    }


    //初始化控件
    private void initWeight() {

        iv_findfragment_scan = (ImageView) getActivity().findViewById(R.id.iv_findfragment_scan);
        ed_findfragment_seek = (TextView) getActivity().findViewById(R.id.ed_findfragment_seek);

        nestedScrollView = (NestedScrollView) getActivity().findViewById(ss);
        fll_flowlayout_show = (FlowLayout) getActivity().findViewById(R.id.fll_flowlayout_show);
        tv_findfragment_more = (TextView) getActivity().findViewById(R.id.tv_findfragment_more);
        lay_findfragment_xingqu = (LinearLayout) getActivity().findViewById(R.id.lay_findfragment_xingqu);
        lay_findfragment_huati = (LinearLayout) getActivity().findViewById(R.id.lay_findfragment_huati);
        lay_findfragment_huodong = (LinearLayout) getActivity().findViewById(R.id.lay_findfragment_huodong);
        lay_findfragment_xiaohei = (LinearLayout) getActivity().findViewById(R.id.lay_findfragment_xiaohei);
        lay_findfragment_yuanchuang = (LinearLayout) getActivity().findViewById(R.id.lay_findfragment_yuanchuang);
        lay_findfragment_quanqu = (LinearLayout) getActivity().findViewById(R.id.lay_findfragment_quanqu);
        lay_findfragment_youxi = (LinearLayout) getActivity().findViewById(R.id.lay_findfragment_youxi);
        lay_findfragment_zhoubian = (LinearLayout) getActivity().findViewById(R.id.lay_findfragment_zhoubian);

        //设置点击事件
        iv_findfragment_scan.setOnClickListener(this);
        tv_findfragment_more.setOnClickListener(this);
        lay_findfragment_xingqu.setOnClickListener(this);
        lay_findfragment_huati.setOnClickListener(this);
        lay_findfragment_huodong.setOnClickListener(this);
        lay_findfragment_xiaohei.setOnClickListener(this);
        lay_findfragment_yuanchuang.setOnClickListener(this);
        lay_findfragment_quanqu.setOnClickListener(this);
        lay_findfragment_youxi.setOnClickListener(this);
        lay_findfragment_zhoubian.setOnClickListener(this);
    }


    @Override
    public void onClick(View view) {

        //点击事件的详细情况
        switch (view.getId()) {
            case R.id.iv_findfragment_scan:
                break;
            case R.id.tv_findfragment_more:
                ViewGroup.LayoutParams lp = nestedScrollView.getLayoutParams();
                if (STATUS == 0) {
                    lp.height = nestedScrollView.getHeight() + 180;
                    nestedScrollView.setLayoutParams(lp);
                    STATUS = 1;
                } else {
                    lp.height = nestedScrollView.getHeight() - 180;
                    nestedScrollView.setLayoutParams(lp);
                    STATUS = 0;
                }
                break;
            case R.id.lay_findfragment_xingqu:
                break;
            case R.id.lay_findfragment_huati:
                startActivity(new Intent(getActivity(), TopicActivity.class));
                break;
            case R.id.lay_findfragment_huodong:
                startActivity(new Intent(getActivity(), ActivityCenterActivity.class));
                break;
            case R.id.lay_findfragment_xiaohei:
                break;
            case R.id.lay_findfragment_yuanchuang:
                startActivity(new Intent(getActivity(), OriginalRankActivity.class));
                break;
            case R.id.lay_findfragment_quanqu:
                startActivity(new Intent(getActivity(), AllareasRankActivity.class));
                break;
            case R.id.lay_findfragment_youxi:
                startActivity(new Intent(getActivity(), GameCentreActivity.class));
                break;
            case R.id.lay_findfragment_zhoubian:

                Intent intent = new Intent(getActivity(), WebViewActivity.class);
                intent.putExtra("web", Network.SHOP);
                intent.putExtra("title", "bilibili - 周边商城");
                startActivity(intent);
                break;
        }
    }
}
